package com.example.hello.hello.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.Toast;

import com.example.hello.hello.R;
import com.example.hello.hello.activity.LoginActivity;
import com.example.hello.hello.base.BaseFragment;


public class MainFragment extends BaseFragment {


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initTitleBar();
        setMidTxt("首页");
        setLeftVisibility(false);
        setRightImg(getResources().getDrawable(R.mipmap.nav_porfile));
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

        final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe);
        swipeView.setColorScheme(android.R.color.holo_blue_dark, android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_green_light);
        swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeView.setRefreshing(true);
                Toast.makeText(getActivity(), "refresh", Toast.LENGTH_SHORT).show();

                swipeView.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        // 更新数据
                        Toast.makeText(getActivity(), "完成", Toast.LENGTH_SHORT).show();
                        // 更新完后调用该方法结束刷新
                        swipeView.setRefreshing(false);
                    }
                },2000);

            }
        });
    }

    @Override
    protected void onClickLeftBtn() {

    }

    @Override
    protected void onClickReghtBtn() {
        Intent intent = new Intent(getActivity(), LoginActivity.class);
        startActivity(intent);
    }


}
